package com.ctrlspace.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

public class User implements JSONAware {

	private int id;

	private String username;
	
	private String email;

	private String firstName;

	private String lastName;

	private Date lastLogin;

	private int lastIp;
	
	private boolean isLogged;
	
	private List<WorkspaceUnit> workspaces;
	
	private int activeWorkspaceId;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getLastLogin() {
		return lastLogin;
	}

	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}

	public int getLastIp() {
		return lastIp;
	}

	public void setLastIp(int lastIp) {
		this.lastIp = lastIp;
	}

	public void setLogged(boolean isLogged) {
		this.isLogged = isLogged;
	}

	public boolean isLogged() {
		return isLogged;
	}

	public void setWorkspaces(List<WorkspaceUnit> workspaces) {
		this.workspaces = workspaces;
	}

	public List<WorkspaceUnit> getWorkspaces() {
		return workspaces;
	}

	public void setActiveWorkspaceId(int activeWorkspaceId) {
		this.activeWorkspaceId = activeWorkspaceId;
	}

	public int getActiveWorkspaceId() {
		return activeWorkspaceId;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		JSONObject output = new JSONObject();
		output.put("userId", getId());
		output.put("isLogged", isLogged());
		output.put("username", getUsername());
		output.put("email", getEmail());
		output.put("firstName", getFirstName());
		output.put("lastName", getLastName());
		output.put("lastLogin", formatter.format(getLastLogin()));
		output.put("lastIp", getLastIp());
		output.put("activeWorkspaceId", getActiveWorkspaceId());
		return output.toJSONString();
	}

}
